<?php

require './configs/config.php';
//require './models/DB.class.php';
//require './controllers/IndexController.php';
//require './controllers/UserController.php';
//require './controllers/GoodsController.php';

function mvc_autoload($classname)
{
//    echo $classname.'<br>';
    if (file_exists("./models/{$classname}.class.php")) {
        require "./models/{$classname}.class.php";
    } elseif (file_exists("./controllers/{$classname}.php")) {
        require "./controllers/{$classname}.php";
    } else {
        header("HTTP/1.0 404 not found");
        echo '<h1>404 Not Found -- 入口</h1>';
        exit;
    }
}

// 导入Smarty
require './libs/Smarty.class.php';
// 注册给定的函数作为 __autoload 的实现
spl_autoload_register('mvc_autoload');
// 实例化
//$smarty = new Smarty();
//var_dump($smarty);


// 获取用户的传递的参数
// 控制器名
$c = (!empty($_GET['c'])) ? $_GET['c'] : 'Index';
// 方法名
$a = (!empty($_GET['a'])) ? $_GET['a'] : 'index';

// 拼接类名
$classname = $c . 'Controller';

// 实例化对象
$controller = new $classname();
// 调用方法
$controller->$a();



